package com.xncoding.ConcurrentHashMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapTest {
    private static final Map<String, Long> wordCounts = new ConcurrentHashMap<String, Long>();
    public static void main(String[] args) {
        for (int i = 0; i <= 99; i++) {
            new Thread(){
                public void run() {
                    Long oldValue = wordCounts.get("a");
                    Long newValue = (oldValue == null) ? 1L : oldValue + 1;
                    wordCounts.put("a", newValue);
                };
            }.start();
        }
        System.out.println(wordCounts);
    }
}
